/**
 * 
 */
package org.tarpoon.nexus.monitoring;

import javax.inject.Inject;
import javax.inject.Named;

import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.access.Action;
import org.sonatype.nexus.proxy.item.AbstractStorageItem;
import org.sonatype.nexus.proxy.repository.ProxyRepository;
import org.sonatype.nexus.proxy.repository.Repository;
import org.sonatype.nexus.proxy.repository.RequestProcessor;
import org.sonatype.plexus.appevents.ApplicationEventMulticaster;

/**
 * @author drouet
 * 
 */
@Named("statisticsColector")
public class StatisticsRequestProcessor extends AbstractLogEnabled implements RequestProcessor {
  @Inject
  private ApplicationEventMulticaster applicationEventMulticaster;

  /*
   * (non-Javadoc)
   * 
   * @see org.sonatype.nexus.proxy.repository.RequestProcessor#process(org.sonatype.nexus.proxy.repository.Repository, org.sonatype.nexus.proxy.ResourceStoreRequest,
   * org.sonatype.nexus.proxy.access.Action)
   */
  public boolean process(Repository repository, ResourceStoreRequest request, Action action) {
    getLogger().info("STATS process - {REPO ID:" + repository!=null?repository.getId():"NULL" + "}");
    getLogger().info("STATS process - {REQ PATH:" + request.getRequestPath() + "}");
    getLogger().info("STATS process - {ACT :" + action.toString() + "}");
    System.out.println("STATS process - {REPO ID:" + repository.getId() + "}");
    System.out.println("STATS process - {REQ PATH:" + request.getRequestPath() + "}");
    System.out.println("STATS process - {ACT :" + action.toString() + "}");
    return true;
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.sonatype.nexus.proxy.repository.RequestProcessor#shouldCache(org.sonatype.nexus.proxy.repository.ProxyRepository, org.sonatype.nexus.proxy.item.AbstractStorageItem)
   */
  public boolean shouldCache(ProxyRepository repository, AbstractStorageItem item) {
    System.out.println("STATS shouldCache - {REPO ID:" + repository.getId() + "}");
    System.out.println("STATS shouldCache - {ITEM:" + item.getName() + "}");
    return true;
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.sonatype.nexus.proxy.repository.RequestProcessor#shouldProxy(org.sonatype.nexus.proxy.repository.ProxyRepository, org.sonatype.nexus.proxy.ResourceStoreRequest)
   */
  public boolean shouldProxy(ProxyRepository repository, ResourceStoreRequest request) {
    System.out.println("STATS shouldProxy - {REPO ID:" + repository.getId() + "}");
    System.out.println("STATS shouldProxy - {REQ:" + request.getRequestPath() + "}");
    return true;
  }

}
